#ifndef __THREAD_H
#define __THREAD_H

#include "../rtx/rtx_os.h"

#define THREAD_INFO(NAME, STACK_SIZE, PRIORITY)                                \
    static uint64_t NAME##_cb_men[(osRtxThreadCbSize + 7) / 8];                \
    static uint64_t NAME##_stack_mem[(STACK_SIZE + 7) / 8];                    \
    static osThreadId_t NAME##_id;                                             \
    static inline void NAME##_start(osThreadFunc_t func, void *args) {         \
        osThreadAttr_t attr = {                                                \
            .name = #NAME,                                                     \
            .attr_bits = osThreadDetached,                                     \
            .cb_mem = NAME##_cb_men,                                           \
            .cb_size = osRtxThreadCbSize,                                      \
            .stack_mem = NAME##_stack_mem,                                     \
            .stack_size = STACK_SIZE,                                          \
            .priority = PRIORITY,                                              \
            .tz_module = 0,                                                    \
            .reserved = 0,                                                     \
        };                                                                     \
        NAME##_id = osThreadNew(func, args, &attr);                            \
    }

#endif
